package service;
import java.util.Scanner;

import Dao.DealUtil;

import valueObject.Card;
import valueObject.Customer;

public class Test {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("输入:");
		String input = sc.nextLine();
		String[] strs = input.split(" ");
		if (strs[1].equalsIgnoreCase("add-member")) {
			Customer cust = new Customer();
			cust.setCustName(strs[2]);
			cust.setAddress(strs[3]);
			cust.setJob(strs[4]);
			DealUtil du = new DealUtil();
			du.addCustomer(cust);
			int id = du.getNowId("CUSTOMER", "CUSTOMER_ID");
			System.out.println("ok. " + strs[2] + "'s member id is " + id);
		} else if (strs[1].equalsIgnoreCase("add-card")) {
			Card card = new Card();
			String name = strs[2];
			DealUtil du = new DealUtil();
			Customer[] value = du.qryCust(name);
			if (value.length > 1) {
				System.out.println("The number of customer with this name is more than one!");
			} else if (value.length == 1) {
				card.setCardType(strs[3]);
				card.setCustomerId(value[0].getCustId());
				if (strs.length == 5) {
					card.setUseTime(Integer.parseInt(strs[4]));
				}
				du.addCard(card);
				int id = du.getNowId("CARD", "CARD_ID");
				if (strs[3].equalsIgnoreCase("年卡")){
					System.out.println("ok. A new " + strs[3]+" added to "+strs[2]);
				}else if ((strs[3].equalsIgnoreCase("次卡"))){
					System.out.println("ok. A new " + strs[3]+" with " +strs[4]+" times added to "+strs[2]);
				}else{
					System.out.println("Please input correct data!");
				}
			} else {
				System.out.println("The customer with this name doesn't exist!");
			}
		} else {
			System.out.println("Please input correct data!");
		}
	}
}
